window.addEventListener('load', function () {
    var header = document.querySelector('.header');
    var i1 = document.querySelector('.header .w>i');
    var box1 = document.querySelector('.box1');
    var box1_x = document.querySelector('.box1_x');
    var tab = document.querySelector('.tab_1');
    var lis = document.querySelectorAll('.tab_1 li');
    var inp = document.querySelector('.box2 input');
    var but = document.querySelector('.box2 button');
    var h_left = document.querySelector('.h_left');
    var tab_bottom = document.querySelector('.tab_bottom');
    var a_mouse = document.querySelectorAll('.body_1_hd a');
    var li_mouse = document.querySelectorAll('.body_1_hd li');
    var a_mouse2 = document.querySelectorAll('.footer_bd a');
    var a_mouse3 = document.querySelector('.right_2_bd a');
    var li_mouse_l = document.querySelectorAll('.r_2_bd_l');
    var li_mouse_r = document.querySelectorAll('.r_2_bd_r');;
    var headerTop = header.offsetHeight;
    //设置一个开关
    var flag = true;
    // 页面下拉,开始运行
    document.addEventListener('scroll', function () {
        if (window.pageYOffset >= headerTop) {
            i1.style.display = 'none';
            box1.style.display = 'block';
            //只运行一次的开关(已经打开过,变成false)
            if (flag) {
                tab.style.top = '-45px';
                tab_bottom.style.top = '-45px';
                flag = false;
            }
            //移入频道出现tab栏
            box1.addEventListener('mouseover', function () {
                tab.style.top = '0';
                tab_bottom.style.top = '0';
            })
            //移出频道消去tab栏
            box1.addEventListener('mouseout', function () {
                tab.style.top = '-45px';
                tab_bottom.style.top = '-45px';
            })
            //移入tab,tab持续状态
            tab.addEventListener('mouseover', function () {
                tab.style.top = '0';
                tab_bottom.style.top = '0';
            })
            //移出tab,tab状态消失
            tab.addEventListener('mouseout', function () {
                tab.style.top = '-45px';
                tab_bottom.style.top = '-45px';
            })
            //移入logo,小盒子出现
            h_left.addEventListener('mouseover', function () {
                box1_x.style.display = 'block';
            })
            //移出logo,小盒子消失
            h_left.addEventListener('mouseout', function () {
                box1_x.style.display = 'none';
            })
        } else {
            // 页面还原,停止运行
            i1.style.display = 'block';
            box1.style.display = 'none';
            tab.style.top = '0';
            tab_bottom.style.top = '0';
            //关闭开关(变成true)
            flag = true;
            //页面没下拉,去掉效果
            tab.addEventListener('mouseout', function () {
                tab.style.top = '0';
                tab_bottom.style.top = '0';
            })
            //页面没下拉,去掉效果
            h_left.addEventListener('mouseover', function () {
                box1_x.style.display = 'none';
            })
        }
    })
    //获取焦点,搜索框变红色,失去焦点,搜索框恢复
    inp.addEventListener('focus', function () {
        inp.style.border = '1px solid red';
        inp.style.borderRight = '0';
        but.style.border = '1px solid red';
        but.style.borderLeft = '0';
    })
    inp.addEventListener('blur', function () {
        inp.style.border = '0';
        but.style.border = '0';
    })
    //tab切换效果
    for (var i = 0; i < lis.length; i++) {
        //鼠标点击tab切换
        lis[i].addEventListener('click', function () {
            for (var j = 0; j < lis.length; j++) {
                lis[j].classList.remove('click');
            }
            this.classList.add('click');
        })
        //鼠标移入tab切换
        lis[i].addEventListener('mouseover', function () {
            for (var k = 0; k < lis.length; k++) {
                lis[k].classList.remove('mouse');
            }
            this.classList.add('mouse');
        })
    }
    for (var i = 0; i < a_mouse.length; i++) {
        a_mouse[i].addEventListener('mouseover', function () {
            this.style.color = '#fc589f';
        })
        a_mouse[i].addEventListener('mouseout', function () {
            this.style.color = '';
        })
    }
    for (var i = 0; i < li_mouse.length; i++) {
        li_mouse[i].addEventListener('mouseover', function () {
            this.style.backgroundColor = '#fc589f';
            this.style.color = "#fff";
        })
        li_mouse[i].addEventListener('mouseout', function () {
            this.style.backgroundColor = '';
            this.style.color = "#ccc";
        })
    }
    for (var i = 0; i < a_mouse2.length; i++) {
        a_mouse2[i].addEventListener('mouseover', function () {
            this.style.textDecoration = 'underline';
        })
        a_mouse2[i].addEventListener('mouseout', function () {
            this.style.textDecoration = 'none';
        })
    }
    a_mouse3.addEventListener('mouseover', function () {
        this.style.textDecoration = 'underline';
    })
    a_mouse3.addEventListener('mouseout', function () {
        this.style.textDecoration = 'none';
    })
    for (var i = 0; i < li_mouse_l.length; i++) {
        li_mouse_l[i].index = i;
        li_mouse_l[i].addEventListener('mouseover', function () {
            var index = this.index;
            li_mouse_r[index].children[0].style.color = 'red';
        })
        li_mouse_l[i].addEventListener('mouseout', function () {
            var index = this.index;
            li_mouse_r[index].children[0].style.color = '#666';
        })
    }
    for (var i = 0; i < li_mouse_r.length; i++) {
        li_mouse_r[i].index = i;
        li_mouse_r[i].addEventListener('mouseover', function () {
            var index = this.index;
            li_mouse_r[index].children[0].style.color = 'red';
        })
        li_mouse_r[i].addEventListener('mouseout', function () {
            var index = this.index;
            li_mouse_r[index].children[0].style.color = '#666';
        })
    }
})